<?php
header ( 'Content-Type:text/html; charset=UTF-8' );
session_start ();
@$qk = $_REQUEST['qk'];
$pdo = new PDO ( 'mysql:dbname=atm;charset=utf8', 'root' );
$s = $pdo->prepare ( 'select ye from username where name=:name' );
$s->execute (array(
    'name'=>$_SESSION ['user']
));
$data = $s->fetch ( PDO::FETCH_NAMED );
if ($qk>0) {
    if (($data['ye']-$qk)>=0){
    $s = $pdo->prepare('update username set ye=:xx where name=:name');
    $isok = $s->execute(array(
        'xx' => ($data['ye']-$qk),
        'name'=>$_SESSION ['user']
    ));
    if ($isok){
     $arr=array('zt'=>true,'ye'=>($data['ye']-$qk),'fhwb'=>'取款成功');
        echo json_encode($arr);   
    }else {
        $arr=array('zt'=>false,'ye'=>$data['ye'],'fhwb'=>'取款失败');
        echo json_encode($arr);
    }
    }else{
        $arr=array('zt'=>false,'ye'=>$data['ye'],'fhwb'=>'取款金额不足');
        echo json_encode($arr);
    }
}else{
    $arr=array('zt'=>false,'ye'=>$data['ye'],'fhwb'=>'取款必须大于零');
    echo json_encode($arr);
}


